package org.wiztools.ehcachermireplication;

import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;

/**
 *
 * @author subhash
 */
public class Main {
    public static void main(String[] arg) {
        if(arg.length != 1) {
            System.err.println("Please enter config path as parameter!");
            System.exit(1);
        }
        
        final String BUCKET_NAME = "sexy_bucket";
        final String KEY_NAME = "sexy_key";
        
        final CacheManager manager = new CacheManager(arg[0]);
        final Ehcache cache = manager.getEhcache(BUCKET_NAME);
        
        while(true) {
            System.out.print("Enter option put, get or exit [p/g/x]: ");
            final String command = System.console().readLine();
            if("p".equals(command)) {
                System.out.print("Enter value: ");
                final String value = System.console().readLine();
                cache.put(new Element(KEY_NAME, value));
            }
            else if("g".equals(command)) {
                Element e = cache.get(KEY_NAME);
                System.out.println("Value: " + (e!=null? e.getValue(): null));
            }
            else if("x".equals(command)) {
                    System.exit(0);
            }
        }
    }
}
